<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
    wrapClassName="ant-modal-cust-warp"
    style="top: 5%; height: 85%; overflow-y: hidden"
  >
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" v-bind="layout" :model="model">
        <a-form-model-item label="昵称" prop="nickname">
          <a-input v-model="model.nickname" disabled />
        </a-form-model-item>

        <a-form-model-item label="会员号" prop="userName">
          <a-input v-model="model.userName" disabled />
        </a-form-model-item>

        <a-form-model-item label="真实姓名" prop="realName">
          <a-input v-model="model.realName" disabled />
        </a-form-model-item>

        <a-form-model-item label="身份证号" prop="idCard">
          <a-input v-model="model.idCard" disabled />
        </a-form-model-item>

        <!-- <a-form-model-item label="会员等级" required prop="level">
          <a-input v-model="model.level"  />
        </a-form-model-item> -->


        <a-form-model-item label="会员等级" prop="level">
          <a-select v-model="model.level" placeholder="请选择会员等级" :getPopupContainer= "(target) => target.parentNode">
            <a-select-option v-for="(item, index) in levelOptions" :key="index.toString()" :value="item.value">
              {{ item.label }}
            </a-select-option>
          </a-select>
        </a-form-model-item>    


      </a-form-model>
    </a-spin>
  </a-modal>
</template>

<script>
import { setMemberVip,ajaxGetDictItems } from '@/api/api'
export default {
  name: 'WxUserModal',
  data() {
    return {
      title: '操作',
      visible: false,
      disableSubmit: false,
      model: {},
      levelOptions:[],
      layout: {
        labelCol: { span: 3 },
        wrapperCol: { span: 14 },
      },
      confirmLoading: false,
    }
  },
  created() {
    this.getDictItem();
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model));
    this.model.level=1;
    
  },
  methods: {
    getDictItem() {
      //根据字典Code, 初始化字典数组
      ajaxGetDictItems('member_level', null).then((res) => {
        if (res.code === 20000) {
          this.levelOptions = res.data;
        }
      })
    },
    add() {
      this.visible = true
      this.edit(this.modelDefault)
    },
    edit(record) {
      this.model = Object.assign({}, this.defaultModel, record)
      this.visible = true
      this.model.level=this.model.level.toString();
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      const that = this
      const params = that.model
      setMemberVip(params).then((res) => {
      if (res.code === 20000) {
          that.$message.success('设置成功！')
          that.close()
          that.$emit('ok')
      }
      })


    //   let obj
    //   if (!that.model.id) {
    //     obj = addBusiness(params)
    //   } else {
    //     obj = editBusiness(params)
    //   }
    //   obj.then((res) => {
    //     if (res.code === 20000) {
    //       that.$message.success('添加成功！')
    //       that.close()
    //       that.$emit('ok')
    //     } else {
    //       that.$message.warning('添加失败！')
    //       that.close()
    //     }
    //   })
    },
    handleCancel() {
      this.close()
    },
  },
}
</script>

<style scoped>
</style>